﻿using System;

using System.Collections.Generic;
using System.Text;

namespace Silvermoon.Controls.Classes
{
    /// <summary>
    /// Class to enumerate Items for a VirtualItemCollection.
    /// </summary>
    internal class VirtualItemEnumerator : IEnumerator<ItemBase>
    {
        private VirtualItemCollection list;
        int index = -1;

        public VirtualItemEnumerator(VirtualItemCollection list)
            : base()
        {
            this.list = list;
        }

        #region IEnumerator<ItemBase> Members

        public ItemBase Current { get { return list[index]; } }

        #endregion

        #region IDisposable Members

        public void Dispose()
        {
        }

        #endregion

        #region IEnumerator Members

        object System.Collections.IEnumerator.Current
        {
            get { return list[index]; }
        }

        public bool MoveNext()
        {
            int c = list.ItemCount;

            do
            {
                index++;
                if (index >= c) break;
            } while (list[index] == null);
            return index < c;
        }

        public void Reset()
        {
            index = -1;
            MoveNext();
        }

        #endregion
    }
}
